* Replication File "Asymmetric Crime Dynamics In and Out of Lockdowns"
* Author: Ruben Poblete-Cazenave
* Date: February 2, 2024.
clear all
set more off
program drop _all
macro drop _all
capture log close

*-------------------------------------------------------------------------------
* Figure 6 - recidivism
*-------------------------------------------------------------------------------
use "database_recidivism.dta", clear
* TIME VARIABLES
	gen first = mdy(1, 1, year(date)) + 7 - dow(mdy(1, 1, year(date)))
		replace first = mdy(1, 1, year(date)) if dow(mdy(1, 1, year(date))) == 0
		format first %td
		
	gen week_no_year= ceil((date + 1 - first)/7)
		label var week_no_year "Week no (starting from Sunday to Saturday) within a Year"

	* to have 7 days week I need to change the missing ( 52 weeks a year.)
	replace week_no_year= 0 if week_no_year== 53 & year == 2017	/* moving the 31 dec 2017 to the first week in 2018 */
	replace week_no_year= 0 if week_no_year== 52 & year == 2018	/* moving the days after 30 dec in 2018 to the first week in 2019 */
	replace week_no_year= 0 if week_no_year== 52 & year == 2019	/* moving the days after 29 dec in 2019 to the first week in 2020 */
		
	egen first_2 = min(first)
		format first_2 %td
		
	gen week_no_all = ceil((date + 1 - first_2)/7)
		label var week_no_all "Week no (starting from Sunday to Saturday). All Years."

* Create variable for dynamic impact (event study)		
		gen week_t1 = week_no_year - 12
		label var week_t1 "Week no (Sunday to Saturday). treatment week=0"		
		
order week_t1		
keep if week_t1>=-11 & week_t1<=18 	



 

	*-------------------------------------------------------------------------------
	* Dummies for each week
	*-------------------------------------------------------------------------------
	foreach num of numlist 11(-1)1 {
		gen week_n`num' = (week_t1 == - `num')
		label var week_n`num' "t=-`num'"
	}

	foreach num of numlist 0(1)18 {
		gen week_`num' = (week_t1 == `num')
		label var week_`num' "t=`num'"
	}			

	 
* (1) RECIDIVISM ALL CRIMES

			capture clonevar copy_week_n1 = week_n1
			replace week_n1 = 0

			* Regress, adding the new variable
			areg recidivist week_n11 - week_n1 week_0 week_1 - week_18 copy_week_n1 $block_controls  if year == 2020 , cluster(district)  absorb(district)  
			* Coefplot
			coefplot, keep( week_*)   xline(12 16 18 22 26 28, lcolor(gray) lpattern(dash) lwidth(vthin)) vertical xlabel(,angle(45) labsize(small)) graphregion(fcolor(white) lcolor(white)) baselevels omitted yline(0, lpattern(dash) lcolor(gray)) ytitle("Recidivism")
			graph export "tables and figures\Eventstudy_recidivism.pdf" ,replace 			


* (2) RECIDIVISM IN PROPERTY CRIMES

			* Regress, adding the new variable
			areg recidivist week_n11 - week_n1 week_0 week_1 - week_18 copy_week_n1 $block_controls  if year == 2020 & property_crime == 1, cluster(district)  absorb(district)  
			* Coefplot
			coefplot, keep( week_*)   xline(12 16 18 22 26 28, lcolor(gray) lpattern(dash) lwidth(vthin)) vertical xlabel(,angle(45) labsize(small)) graphregion(fcolor(white) lcolor(white)) baselevels omitted yline(0, lpattern(dash) lcolor(gray)) ytitle("Recidivism")		
					

* (3) RECIDIVISM IN PERSONAL CRIMES
			* Regress, adding the new variable
			areg recidivist week_n11 - week_n1 week_0 week_1 - week_18 copy_week_n1 $block_controls  if year == 2020 & personal_crime == 1, cluster(district)  absorb(district)  
			* Coefplot
			coefplot, keep( week_*)   xline(12 16 18 22 26 28, lcolor(gray) lpattern(dash) lwidth(vthin)) vertical xlabel(,angle(45) labsize(small)) graphregion(fcolor(white) lcolor(white)) baselevels omitted yline(0, lpattern(dash) lcolor(gray)) ytitle("Recidivism")
			